﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <Converters:MetroTabItemCloseButtonWidthConverter x:Key="MetroTabItemCloseButtonWidthConverter" />

    <Style TargetType="{x:Type Controls:MetroTabItem}">
        <Setter Property="FocusVisualStyle"
                Value="{x:Null}" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="Padding"
                Value="6,2,6,2" />
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
        <Setter Property="VerticalContentAlignment"
                Value="Stretch" />
        <Setter Property="MinWidth"
                Value="5" />
        <Setter Property="MinHeight"
                Value="5" />
        <Setter Property="BorderThickness"
                Value="0" />
        <Setter Property="BorderBrush"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <!-- special property for header font size -->
        <Setter Property="Controls:ControlsHelper.HeaderFontSize"
                Value="{DynamicResource TabItemFontSize}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:MetroTabItem}">
                    <Border x:Name="Border"
                            Margin="{TemplateBinding Padding}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Background="{TemplateBinding Background}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <StackPanel Orientation="Horizontal">
                            <ContentPresenter x:Name="ContentSite"
                                              Margin="2,1,2,1"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              TextElement.FontSize="{TemplateBinding Controls:ControlsHelper.HeaderFontSize}"
                                              TextElement.FontStretch="{TemplateBinding Controls:ControlsHelper.HeaderFontStretch}"
                                              TextElement.FontWeight="{TemplateBinding Controls:ControlsHelper.HeaderFontWeight}"
                                              TextElement.Foreground="{TemplateBinding Foreground}"
                                              ContentSource="Header"
                                              RecognizesAccessKey="True" />
                            <Button x:Name="PART_CloseButton"
                                    Style="{DynamicResource ChromelessButtonStyle}"
                                    Background="{DynamicResource GrayNormalBrush}"
                                    Width="{TemplateBinding Controls:ControlsHelper.HeaderFontSize, Converter={StaticResource MetroTabItemCloseButtonWidthConverter}}"
                                    Height="{Binding RelativeSource={RelativeSource Self}, Path=Width, Mode=OneWay}"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Top"
                                    Margin="0 0 2 0"
                                    IsTabStop="False"
                                    Command="{TemplateBinding CloseTabCommand}"
                                    CommandParameter="{TemplateBinding CloseTabCommandParameter}">
                                <Button.OpacityMask>
                                    <VisualBrush Stretch="Uniform"
                                                 Visual="{DynamicResource appbar_close}" />
                                </Button.OpacityMask>
                            </Button>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected"
                                 Value="true">
                            <Setter Property="TextElement.Foreground"
                                    TargetName="ContentSite"
                                    Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsSelected"
                                 Value="false">
                            <Setter Property="TextElement.Foreground"
                                    TargetName="ContentSite"
                                    Value="{DynamicResource GrayNormalBrush}" />
                        </Trigger>
                        <Trigger SourceName="ContentSite"
                                 Property="IsMouseOver"
                                 Value="True">
                            <Setter Property="TextElement.Foreground"
                                    TargetName="ContentSite"
                                    Value="{DynamicResource GrayHoverBrush}" />
                            <Setter TargetName="PART_CloseButton"
                                    Property="Background"
                                    Value="{DynamicResource GrayHoverBrush}" />
                        </Trigger>
                        <Trigger SourceName="PART_CloseButton"
                                 Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="PART_CloseButton"
                                    Property="Background"
                                    Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>